package com.tjetc.controller;
import com.aliyuncs.exceptions.ClientException;
import com.tjetc.domain.CheckRecord;
import com.tjetc.service.CheckRecordService;
import com.tjetc.service.impl.CheckRecordServiceImpl;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

/**
 * (check_record)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/check_record")
public class CheckRecordController {
/**
* 服务对象
*/
@Resource
private CheckRecordService checkRecordService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public CheckRecord selectOne(Integer id) {
        return checkRecordService.selectByPrimaryKey(id);
    }
    @PostMapping("addJiancha")
    public Result addJiancha(@RequestBody CheckRecord checkRecord) {
        return checkRecordService.addJiancha(checkRecord);
    }
@RequestMapping("getPNmaeDNameDate")
    public Result getPNmaeDNameDate(
            @RequestParam("patientName")String patientName,
            @RequestParam("doctorName")String doctorName,
            @RequestParam("startTime")String startTime,
            @RequestParam("endTime")String endTime,
            @RequestParam("pageNum")Integer pageNum,
            @RequestParam("pageSize")Integer pageSize) {
        return checkRecordService.getPNmaeDNameDate(patientName, doctorName, startTime, endTime, pageNum, pageSize);
    }
    @RequestMapping("add")
    public Result add(
            @RequestParam("name")String name,
            @RequestParam("address")String address,
            @RequestParam("rankId")Integer rankId,
            @RequestParam("resultDesc")String resultDesc,
            @RequestParam("resultContent")String resultContent,
            @RequestParam("type")String type,
            @RequestParam(value = "file",required = false) MultipartFile file
    ) throws IOException, ClientException, com.aliyuncs.exceptions.ClientException {
        CheckRecord checkRecord=new CheckRecord();
        checkRecord.setName(name);
        checkRecord.setAddress(address);
        checkRecord.setRankId(rankId);
        checkRecord.setResultDesc(resultDesc);
        checkRecord.setResultContent(resultContent);
        checkRecord.setType(type);

        Result result= checkRecordService.insertOne(checkRecord,file);
        return result;
    }


    //updateInspect
    @RequestMapping("updateInspect")
    public Result updateInspect(
            @RequestParam("id")Integer id,
            @RequestParam("name")String name,
            @RequestParam("address")String address,
            @RequestParam("rankId")Integer rankId,
            @RequestParam("resultDesc")String resultDesc,
            @RequestParam("resultContent")String resultContent,
            @RequestParam("type")String type,
            @RequestParam(value = "file",required = false) MultipartFile file
    ) throws IOException, ClientException, com.aliyuncs.exceptions.ClientException {
        CheckRecord checkRecord=new CheckRecord();
        checkRecord.setId(id);
        checkRecord.setName(name);
        checkRecord.setAddress(address);
        checkRecord.setRankId(rankId);
        checkRecord.setResultDesc(resultDesc);
        checkRecord.setResultContent(resultContent);
        checkRecord.setType(type);
        checkRecord.setCheckTime(new Date());

        Result result= checkRecordService.updateInspect(checkRecord,file);
        return result;
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */

}
